import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

/**
 * 〈一句话功能简述〉<br>
 * 〈文件操作工具类〉
 *
 * @author suxiaomeng
 * @create 2020/3/16
 * @since 1.0.0
 */
public class FileUtil {
    /**
     * 递归读取文件路径下的所有文件
     *
     * @param path
     * @param fileNameList
     * @return
     */
    public static ArrayList<String> readFiles1(String path, ArrayList<String> fileNameList) {
        File file = new File(path);
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    readFiles1(files[i].getName(), fileNameList);
                } else {
                    String path1 = files[i].getName();
                    String fileName = path1.substring(path1.lastIndexOf("\\") + 1);
                    if (fileName.endsWith(".blv"))
                        fileNameList.add("file '" + fileName +"'");
                }
            }
        } else {
            String path1 = file.getPath();
            String fileName = path1.substring(path1.lastIndexOf("\\") + 1);
            fileNameList.add(fileName);
        }
        return fileNameList;
    }

    /**
     * 将内容输出到（追加）txt文件保存
     *
     * @param content
     * @throws IOException
     */
    public static void outputToTxt(String content, String outputPath) throws IOException {
        FileWriter fw = new FileWriter(outputPath,true);//追加内容
        PrintWriter pw = new PrintWriter(fw);
        pw.println(content);
        pw.close();
        fw.close();
        pw.flush();
    }
}
